package com.baizhi.service.impl;


import com.baizhi.dao.BannerMapper;
import com.baizhi.entity.Banner;
import com.baizhi.service.BannerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: renpu
 * @Date: 2019/2/27 9:01
 * @Description:
 */

@Service
@Transactional
public class BannerServiceImpl implements BannerService {
    @Autowired
    private BannerMapper bannerMapper;


    @Override
    public Map selectByPage(int rows, int page) {
        Map map=new HashMap();

        IPage<Banner> iPage=new Page<>(rows,page);

        IPage<Banner> bannerIPage=bannerMapper.selectPage(iPage,null);

        List<Banner> list=bannerIPage.getRecords();

        long count=bannerIPage.getTotal();
        map.put("rows",list);
        map.put("total",count);
        return map;
    }

    @Override
    public void deleteMany(int[] ids) {

        List<Integer> list=new ArrayList<>();
        for (int id:ids) {
           list.add(id);
        }
        bannerMapper.deleteBatchIds(list);
    }

    @Override
    public void add(Banner banner) {

        bannerMapper.insert(banner);
    }

    @Override
    public void update(Banner banner) {
        bannerMapper.updateById(banner);


    }

}
